<?php
class IpAddressesModel extends Models
{
    public $range, $countryId;
	protected $tableName='country_ip_addresses_range';
	
    public function getAll()
    {
        if(!$ranges=$this->findAllModes($this->tableName)) return false;

        $result=array();
        foreach($ranges as $range){
            if($range){
                $this->range        =$this->getRanges($range['ip_addresses_range']);
                $this->countryId    =$range['country_id'];
                $result[]           =$this;
            }
        }

        return $result;
    }

    private function getRanges($range)
    {
        if(!$range) return null;

        $result=array();
        $arrayOfRanges=explode(';', $range);

        foreach($arrayOfRanges as $num=>$range){
            $tmpArr=explode('-', $range);
            if(isset($tmpArr[0]) && isset($tmpArr[1])) $result[$num]=array(str_replace(' ', '', $tmpArr[0]), str_replace(' ', '', $tmpArr[1]));
        }

        return $result;
    }

    public function update($id, $attributes)
    {
        return $this->updateModel($id, $this->tableName, $attributes);
    }

    public function getTableName(){
        return $this->tableName;
    }
}